package com.itheima.d0_feedback;

import java.util.Arrays;
import java.util.Comparator;

public class Demo {

    public static void main(String[] args) {
        Student[] students = new Student[3];
        students[0] = new Student("Jack",18);
        students[1] = new Student("Lily",15);
        students[2] = new Student("Rose",19);

        //需求：对数组students进行按照年龄升序排序
        Arrays.sort(students);

        System.out.println("Arrays.toString(students) = " + Arrays.toString(students));

        //需求：不改变Student类代码的同时，实现年龄的降序排序
        Arrays.sort(students, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return Integer.compare(o2.getAge(),o1.getAge());
            }
        });
        System.out.println("Arrays.toString(students) = " + Arrays.toString(students));


    }
}
